//
//  STBaseController.m
//  OCVVeibo
//
//  Created by leergou on 16/7/19.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

#import "STBaseController.h"
#import "STVisitorView.h"
#import "STOAuthController.h"
#import "STUserAccountVM.h"


@interface STBaseController ()

///** 记录是否登录 */
//@property (nonatomic,assign) BOOL isLogin;
//
///** tableView */
//@property (nonatomic, strong) UITableView *tableView;

/** visitorView */
@property (nonatomic, strong) STVisitorView *visitorView;

@end

@implementation STBaseController

- (void)loadView{
    [super loadView];
    
#warning 没起作用?
//    NSLog(@"baseController-->%d",[STUserAccountVM sharedUserAccountTools].isLogin);
    
    self.isLogin =[STUserAccountVM sharedUserAccountTools].isLogin;
    
    self.isLogin ? self.view = self.tableView : [self setupVisitorView];
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
}

#pragma mark - 按钮监听事件
- (void)loginButtonClick:(UIBarButtonItem *)sender{
    // 加载新浪微博授权页面
    STOAuthController *oauthVc = [[STOAuthController alloc] init];
    
    [self.navigationController presentViewController:[[UINavigationController alloc] initWithRootViewController:oauthVc] animated:YES completion:nil];
}

#pragma mark - setupVisitorView
- (void)setupVisitorView{
    
    self.view = self.visitorView;
    __weak typeof(self) weakSelf = self;
    
    self.visitorView.buttonClick = ^(UIBarButtonItem *sender) {
        [weakSelf loginButtonClick:sender];
    };
    
    [self setupNav];
}

#pragma mark - 设置导航栏
- (void)setupNav{
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:(UIBarButtonItemStylePlain) target:self action:@selector(loginButtonClick:)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:(UIBarButtonItemStylePlain) target:self action:@selector(loginButtonClick:)];
}

#pragma mark - 设置view
- (void)setViewContentWithIconImgName:(NSString *)iconImgName title:(NSString *)title{
    [self.visitorView setViewContentWithIconImgName:iconImgName title:title];
}

#pragma mark - lazy
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
    }
    return _tableView;
}

- (STVisitorView *)visitorView{
    if (!_visitorView) {
        
        _visitorView = [[STVisitorView alloc] init];
    }
    return _visitorView;
}


@end
